#ifndef _DBIMPL_H
#define _DBIMPL_H

#include "stdafx.h"
#include <db/idatabase.h>

typedef enum eFIELD_INDEX {
    FIELD_NAME_INDEX = 1,
    FIELD_TYPE_INDEX = 2,
    FIELD_ISNULL_INDEX = 3,
    FIELD_PK_INDEX = 5,
} FIELD_INDEX;

enum eFIELD_ATTRIBUTE {
    FIELD_IS_NOTNULL = 1,
    FIELD_IS_PK = 99,
};

class CDatabaseImpl : public IDatabase, public IPlugin, public CUnknownImp
{
public:
    CDatabaseImpl(void);
    virtual ~CDatabaseImpl(void);

    BEGIN_STDCOM_MAP
    STDCOM_INTERFACE_ENTRY_UNKNOWN_(IDatabase)
    STDCOM_INTERFACE_ENTRY(IPlugin)
    STDCOM_INTERFACE_ENTRY(IDatabase)
    END_STDCOM_MAP

    // IPlugin
    std_method(Init)(IBase* pRot, IBase* pBase);
    std_method(Uninit)();

    // IDatabase
    std_method(SetOption)(LPCWSTR lpszName, LPCWSTR lpszValue);
    std_method(Connect)();
    std_method_(UINT, IsValid)();
    std_method(Close)();
    std_method(CreateStatement)(IStatement** ppStatement);
    std_method_(UINT, IsTableExist)(LPCSTR lpszName);
    std_method(GetTableInfo)(LPCSTR lpszName, ITableInfo** ppTableInfo);
    std_method(UpdateTable)(ITableInfo* pTableInfo);
    std_method(CreateTableInfo)(LPCSTR lpszName, ITableInfo** ppTableInfo);

private:
    std::string m_strDBName;
    std::map<std::wstring, std::wstring> m_lstOption;
    sqlite3* m_pDB;
};

#endif
